<template>
	<view class="container">
		<!-- 搜索栏 -->
		<view class="search-container">
			<view class="search-box">
				<uni-icons type="search" size="28" color="#999" class="search-icon"></uni-icons>
				<input type="text" placeholder="搜索订单号、用户姓名..." class="search-input" v-model="searchText" />
			</view>
		</view>

		<!-- 筛选和统计 -->
		<view class="filter-bar">
			<view class="stats-info">
				<text class="total-count">共 {{ orders.length }} 条订单</text>
			</view>
			<view class="status-filter">
				<uni-picker mode="selector" :range="statusOptions" @change="onStatusChange" class="status-picker">
					<view class="status-value">
						<text>{{ selectedStatus }}</text>
						<uni-icons type="arrowdown" size="16" color="#fff"></uni-icons>
					</view>
				</uni-picker>
			</view>
		</view>

		<!-- 订单列表 -->
		<view class="order-list">
			<view class="order-item" v-for="(order, index) in orders" :key="index" @click="viewDetail(order.id)">
				<!-- 订单状态标签 - 调整位置避免重叠 -->
				<view class="order-status-badge" :class="getStatusClass(order.status)">
					{{ order.status || '待服务' }}
				</view>

				<view class="order-header">
					<view class="order-number-section">
						<text class="order-number">订单号: {{ order.id }}</text>
						<text class="order-time">{{ order.createTime }}</text>
					</view>
					<!-- 订单金额 - 添加右侧间距避免与状态标签重叠 -->
					<text class="order-amount">¥{{ order.amount }}</text>
				</view>

				<view class="order-content">
					<view class="info-row">
						<uni-icons type="person" size="16" color="#999"></uni-icons>
						<text class="info-text">{{ order.user }}</text>
					</view>

					<view class="info-row">
						<uni-icons type="calendar" size="16" color="#999"></uni-icons>
						<text class="info-text">{{ order预约时间 }}</text>
					</view>

					<view class="info-row">
						<uni-icons type="gear" size="16" color="#999"></uni-icons>
						<text class="info-text service-text">{{ order.services }}</text>
					</view>
				</view>

				<view class="order-footer">
					<button class="detail-btn" @click.stop="viewDetail(order.id)">
						<uni-icons type="eye" size="14" color="#fff"></uni-icons>
						<text>查看详情</text>
					</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// 脚本部分保持不变
	export default {
		data() {
			return {
				searchText: '',
				statusOptions: ['待服务', '服务中', '已完成', '已取消'],
				selectedStatus: '待服务',
				orders: [{
						id: '2021010831213',
						amount: '500',
						user: '张三丰',
						预约时间: '2023-03-10 11:00',
						services: '宝马X5加装轮、清洁车辆、汽车美容',
						createTime: '2022-10-12 11:09'
					},
					{
						id: '2021010831214',
						amount: '1200',
						user: '李四',
						预约时间: '2023-03-11 14:30',
						services: '奔驰C级保养、换机油、轮胎检查',
						createTime: '2022-10-12 15:20',
						status: '服务中'
					},
					{
						id: '2021010831215',
						amount: '800',
						user: '王五',
						预约时间: '2023-03-09 09:15',
						services: '特斯拉Model 3充电系统检查、内饰清洁',
						createTime: '2022-10-11 10:05',
						status: '已完成'
					}
				]
			};
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			onStatusChange(e) {
				this.selectedStatus = this.statusOptions[e.detail.value];
			},
			viewDetail(id) {
				uni.navigateTo({
					url: `/pages/order-mangement/orderdetail/orderdetail?orderId=${id}`
				});
			},
			getStatusClass(status) {
				const statusMap = {
					'待服务': 'status-pending',
					'服务中': 'status-processing',
					'已完成': 'status-completed',
					'已取消': 'status-cancelled'
				};
				return statusMap[status] || 'status-pending';
			}
		}
	};
</script>
<style>
	.container {
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
		min-height: 100vh;
	}

	/* 顶部安全区域 */
	.status-bar {
		height: var(--status-bar-height);
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
	}

	/* 搜索栏 */
	.search-container {
		padding: 20rpx;
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
	}

	.search-box {
		display: flex;
		align-items: center;
		background-color: rgba(255, 255, 255, 0.95);
		border-radius: 50rpx;
		padding: 20rpx 30rpx;
		backdrop-filter: blur(10rpx);
		box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
	}

	.search-icon {
		margin-right: 15rpx;
	}

	.search-input {
		flex: 1;
		font-size: 28rpx;
		color: #333;
		height: 40rpx;
		line-height: 40rpx;
	}

	.search-input::placeholder {
		color: #999;
	}

	/* 筛选栏 */
	.filter-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
		padding: 0 20rpx 20rpx;
	}

	.stats-info {
		display: flex;
		align-items: center;
	}

	.total-count {
		font-size: 26rpx;
		color: rgba(255, 255, 255, 0.9);
		font-weight: 500;
	}

	.status-filter {
		display: flex;
		align-items: center;
	}

	.status-value {
		font-size: 26rpx;
		color: #fff;
		display: flex;
		align-items: center;
		background-color: rgba(255, 255, 255, 0.2);
		padding: 8rpx 16rpx;
		border-radius: 20rpx;
		backdrop-filter: blur(10rpx);
	}

	.status-value text {
		margin-right: 8rpx;
	}

	/* 订单列表 */
	.order-list {
		padding: 20rpx;
	}

	/* 订单项 */
	.order-item {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
		position: relative;
		overflow: hidden;
		transition: all 0.3s ease;
	}

	.order-item:active {
		transform: translateY(2rpx);
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.15);
	}

	.order-header {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		margin-bottom: 25rpx;
		padding-bottom: 20rpx;
		border-bottom: 1px solid #f0f0f0;
		/* 关键修改：添加足够的右侧内边距，为状态标签留出空间 */
		padding-right: 140rpx;
	}

	/* 订单金额样式调整 */
	.order-amount {
		font-size: 32rpx;
		color: #ff6b6b;
		font-weight: 600;
		/* 确保金额文本不会太长导致溢出 */
		white-space: nowrap;
	}

	/* 状态标签位置调整 */
	.order-status-badge {
		position: absolute;
		top: 20rpx;
		right: 20rpx;
		padding: 6rpx 16rpx;
		border-radius: 12rpx;
		font-size: 22rpx;
		font-weight: 500;
		color: #fff;
		/* 确保标签在最上层 */
		z-index: 10;
		/* 限制标签宽度，防止文本过长 */
		max-width: 120rpx;
		text-align: center;
	}

	.status-pending {
		background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
	}

	.status-processing {
		background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
		color: #333;
	}

	.status-completed {
		background: linear-gradient(135deg, #d299c2 0%, #fef9d7 100%);
		color: #333;
	}

	.status-cancelled {
		background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
		color: #333;
	}


	.order-number-section {
		flex: 1;
	}

	.order-number {
		font-size: 30rpx;
		font-weight: 600;
		color: #333;
		display: block;
		margin-bottom: 8rpx;
	}

	.order-time {
		font-size: 24rpx;
		color: #999;
	}



	.order-content {
		margin-bottom: 25rpx;
	}

	.info-row {
		display: flex;
		align-items: center;
		margin-bottom: 15rpx;
	}

	.info-row:last-child {
		margin-bottom: 0;
	}

	.info-text {
		font-size: 26rpx;
		color: #666;
		margin-left: 12rpx;
		flex: 1;
	}

	.service-text {
		line-height: 1.4;
	}

	.order-footer {
		display: flex;
		justify-content: flex-end;
		padding-top: 20rpx;
		border-top: 1px solid #f0f0f0;
	}

	.detail-btn {
		background: linear-gradient(135deg, #2a8cff 0%, #764ba2 100%);
		color: #fff;
		font-size: 26rpx;
		padding: 12rpx 24rpx;
		border-radius: 25rpx;
		display: flex;
		align-items: center;
		box-shadow: 0 4rpx 16rpx rgba(102, 126, 234, 0.3);
		transition: all 0.3s ease;
	}

	.detail-btn text {
		margin-left: 8rpx;
	}

	.detail-btn:active {
		transform: translateY(1rpx);
		box-shadow: 0 2rpx 8rpx rgba(102, 126, 234, 0.4);
	}
</style>